/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.controller.sms;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.admin.controller.GenericController;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.domain.po.SmsCategoryPo;
import com.itttq.gshop.generic.connector.ISmsCategoryConnector;

@RestController
@RequestMapping("sms/category")
public class SmsCategoryController extends GenericController {
	private static final long serialVersionUID = 456162097932773109L;
	@Autowired
	private ISmsCategoryConnector smsCategoryConnector;
	
	/**
	 * 根据条件查询SmsCategoryPo对象，并分页
	 * 
	 * @param smsCategory
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("categorys.html")
	public ModelAndView getSmsCategorys(SmsCategoryPo smsCategory, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/sms/categorys");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		smsCategory.setStart(ppt.getStart());
		smsCategory.setSize(ppt.getSize());
		ResultPageTo<SmsCategoryPo> rpt = smsCategoryConnector.getSmsCategorys(smsCategory);
		this.getPageMv("categorys", mv, rpt);
		mv.addObject("category", smsCategory);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addSmsCategory() {
		ModelAndView mv = new ModelAndView("/sms/categoryAdd");
		
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param id
	 * @return
	 */
	@RequestMapping("view/{id}.html")
	public ModelAndView viewSmsCategory(@PathVariable("id") Integer id) {
		ModelAndView mv = addSmsCategory();
		if(id != null) {
			mv.addObject("category", smsCategoryConnector.getSmsCategory(id));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param id
	 * @return
	 */
	@RequestMapping("edit/{id}.html")
	public ModelAndView editSmsCategory(@PathVariable("id") Integer id) {
		ModelAndView mv = viewSmsCategory(id);
		mv.addObject("op", "edit");
		return mv;
	}
	
	/**
	 * 保存SmsCategoryPo对象，无ID则新增，有ID则更新
	 * 
	 * @param smsCategory
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public ModelAndView saveSmsCategory(SmsCategoryPo smsCategory) {
		smsCategoryConnector.saveSmsCategory(smsCategory);
		return getSmsCategorys(new SmsCategoryPo(), null);
	}

	/**
	 * 根据ID删除SmsCategoryPo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{id}.html")
	@ResponseBody
	public ModelAndView delSmsCategory(@PathVariable("id") Integer id) {
		if(id != null) {
			smsCategoryConnector.delSmsCategory(id);
		}
		return getSmsCategorys(new SmsCategoryPo(), null);
	}
}